// World.h

#pragma once
#ifndef WORLD_H_INCLUDED
#define WORLD_H_INCLUDED

#include "Bitmap.h"

class PlayerState
{
public:
	dword m_dwIPID;			//the full ip4 [in network order or what?] 2 floats	//position of car, first x then y 
	float m_fRotation;		//rotation of car, goes from 0 (zero) to 2 pi 
	float m_fVelocityX;		//velocity of car, first x then y 
	float m_fVelocityY;
	float m_fAccelerationX;	//acceleration of car, first x then y 
	float m_fAccelerationY;
	float m_fThrust;		//the thrust, goes from -1.0f to +1.0f [is it correct to send other players thrust? shouldn't it be up to the local player to send that?] 
	float m_fSteering;		//steering, goes from -1.0f to +1.0f [what is this?] 
	int m_dwScore;		//score for player 
	float m_fGemPosX;		//position of that players gem 
	float m_fGemPosY;
	dword m_dwGemID;		//gem id, should be unique, set to -1 if a player has taken the gem in

	float m_fPositionX;
	float m_fPositionY;

	PlayerState();
	~PlayerState();
	PlayerState(const PlayerState& p_xS);
	PlayerState& operator=(const PlayerState& p_xS);

	bool IsValid() const;
};

class WorldState
{
public:
	enum 
	{
		MaxPlayers=16,
		InvalidPlayerID=0x0,
		InvalidGemID = 0x0,
		Width=100,
		Height=100,
		Radius=5,
		GemRadius = 2, 
		TimeOutTime = 5000
	};

	struct Gem 
	{
		Gem();
		~Gem();

		float m_fGemPosX;
		float m_fGemPosY;

		dword m_dwGemID;
		int m_iLastSpawn;
	};

	DArray<PlayerState> m_axPlayers;
	Gem m_xGem;

	WorldState();
	~WorldState();

	void Clear();
	void Sort();

	//void Init((float)Radius, (float)Width, (float)Height);
	void Update(dword p_dwMyId);
	void Render(Bitmap* p_pxBM);

	void BounceOffWalls(PlayerState* p_xP);
	void CollectCollisions(DArray<POINT>& po_axPairs);
	void CollisionResponse(PlayerState* p_xA,PlayerState* p_xB);

	int FindByID(dword p_dwID) const;
};

#endif // WORLD_H_INCLUDED
